package org.jackysoft.interceptor;

import java.lang.reflect.Method;

import org.jackysoft.entity.Identifiable;

import com.opensymphony.xwork2.ActionInvocation;

public class RemoveInterceptor extends AbstractInterceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2734733443732480681L;

	@Override
	public String intercept(ActionInvocation invokor) throws Exception {
		super.intercept(invokor);
		Method[] beanMethods = bean.getClass().getMethods();
		Method getId = null;

		for (Method m : beanMethods) {
			if (m.isAnnotationPresent(org.jackysoft.annotations.BID.class)) {
				getId = m;
				break;
			}
		}

		if (getId == null)
			throw new RuntimeException(
					"请在 VO 使用 org.jackysoft.annotations.BID 标注业务主键字段!");

		Object id = getId.invoke(bean);
		
		Method serviceRemoveBean = service.getClass().getMethod(SERVICE_REMOVE_BEAN_,Identifiable.class);

		serviceRemoveBean.invoke(service, bean);

		return invokor.invoke();
	}

}
